package mathgame.gui;

import mathgame.core.GameState;

import javax.swing.*;
import java.awt.*;
import java.util.Observable;
import java.util.Observer;

public class MainFrame extends JFrame implements Observer {

    private CardLayout cardLayout;

    public MainFrame() {
        
        cardLayout = new CardLayout();
        GameState gameState = GameState.getGameState();
        gameState.addObserver(this);
        this.getContentPane().setLayout(cardLayout);

        StartPanel card1 = new StartPanel();
        this.add(card1, "1");
        TimeAttackPanel card2 = new TimeAttackPanel();
        this.add(card2, "2");
        PracticePanel card3 = new PracticePanel();
        this.add(card3, "3");
        HighscorePanel card4 = new HighscorePanel();
        this.add(card4, "4");
        ExamplePanel card5 = new ExamplePanel();
        this.add(card5, "5");

        this.setUndecorated(true);
        this.setSize(990, 590);
        this.setVisible(true);
        this.setLocationRelativeTo(null);
    }

    public void update(Observable o, Object arg) {

        if (o instanceof GameState && arg instanceof Integer) {
            if((Integer)arg == 1){
                cardLayout.first(this.getContentPane());
            }
            else if((Integer)arg == 2){
                cardLayout.first(this.getContentPane());
                cardLayout.next(this.getContentPane());
            }
            else if((Integer)arg == 3){
                cardLayout.first(this.getContentPane());
                cardLayout.next(this.getContentPane());
                cardLayout.next(this.getContentPane());
            }
            else if((Integer)arg == 4){
                cardLayout.first(this.getContentPane());
                cardLayout.next(this.getContentPane());
                cardLayout.next(this.getContentPane());
                cardLayout.next(this.getContentPane());
            }
            else if((Integer)arg == 5){
                cardLayout.last(this.getContentPane());
            }
        }
    }


}